from bs4 import BeautifulSoup
import requests
import urllib
import socket
import string
import os
import threading
import time
import datetime
import sys
print(sys.getdefaultencoding())


count = 1
# os.chdir('yy')

#总的查询链接
url = "http://yz.chsi.com.cn/zsml/queryAction.do"



#单独每个详情的链接
singleUrl ="http://yz.chsi.com.cn/zsml/querySchAction.do?ssdm=31&dwmc=复旦大学&mldm=&mlmc=--选择门类--&yjxkdm=0401&zymc="
encodeCompus = urllib.request.quote(singleUrl, safe=string.printable)

print(encodeCompus)

# headers = {'DNT': '1', 'Upgrade-Insecure-Requests': '1',
#            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
#            'Cache-Control': 'ax-age=0',
#            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/602.2.14 (KHTML, like Gecko) Version/10.0.1 Safari/602.2.14'
# }
#如果是post请求，那么就要给values编码，然后放到url里面去
values = {'ssdm' : '31',
    'yjxkdm' : '0401'
}
data = urllib.parse.urlencode(values).encode('utf-8')
req = urllib.request.Request(encodeCompus)

try:
    response = urllib.request.urlopen(req, timeout=10)
    print(response.info())
    respHtml = response.read()
    decodeHtml = respHtml.decode('utf-8')
    print(decodeHtml)

except socket.timeout:
    print("pass")
